package com.config.controller;


import com.config.entity.Students;
import com.config.service.StudentsService;
import com.config.util.PageResult;
import com.config.util.R;
import com.config.vo.StudentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {

	@Autowired
	private StudentsService studentsService;

	@GetMapping("/list")
	public List<Students> list(){
		return studentsService.findAll();
	}

	@GetMapping("/findByPage")
	public PageResult<Students> findByPage(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize){
		return studentsService.findByPage(page,pageSize);
	}
	// 3. 条件查询带分页

	@PostMapping("/search")
	public PageResult<Students> search(@RequestParam("page") Integer page,
									  @RequestParam("pageSize") Integer pageSize,
									  @RequestBody(required = false) StudentVO studentVo){
		return studentsService.search(page,pageSize,studentVo);
	}

	// 4. 保存学生
	@PostMapping("/save")
	public R save(@RequestBody Students student){
		return studentsService.save(student) ? R.ok().message("添加成功！") : R.error().message("添加失败！");
	}
}

